<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 17-8-10
 * Time: 下午4:54
 */

namespace ActionsHttp;

use Data\Account_flow_DAO;
use Data\Restaurant_withdraws;
use Data\Restaurant_withdraws_DAO;

class RestaurantWithdraws extends BaseActionHttp
{
    public function doAction() {
        parent::doAction();
        // 提现金额
        $withdraws = $this->data[WITHDRAWS_AMOUNT];
        // 商铺id
        $restaurant_id = $_SESSION[RESTAURANT_ID];
        $restaurant_id = 1;

        // 已入帐金额
        $account_entry = Account_flow_DAO::getLastRecordByRestauranId($restaurant_id);
        $account_left = 0;
        if ($account_entry) {
            $account_left = $account_entry->getACCOUNT_LEFT();
        }

        // 正在进行中的提现金额
        $withdraws_amount_ing = Restaurant_withdraws_DAO::getRecordByRestaurantId($restaurant_id);

        if (($withdraws_amount_ing+$withdraws)>$account_left) {
            return $this->SendErrMsg("余额不足");
        }

        $withdraws_record = new Restaurant_withdraws(array());
        $withdraws_record->setRESTAURANT_ID($restaurant_id);
        $withdraws_record->setWITHDRAWS_AMOUNT($withdraws);
        Restaurant_withdraws_DAO::insert($withdraws_record);

        // 返回数据
        $this->ResponseDataToCurrentClient();
    }
}